package com.atguigu.lease.app.service.impl;


import com.atguigu.lease.app.mapper.ApartmentFacilityMapper;
import com.atguigu.lease.app.mapper.ApartmentInfoMapper;
import com.atguigu.lease.app.service.ApartmentInfoService;
import com.atguigu.lease.model.bean.ApartmentInfo;
import com.atguigu.lease.model.bean.FacilityInfo;
import com.atguigu.lease.model.vo.apartment.GraphVo;
import com.atguigu.lease.model.vo.app.ApartmentDetailVo;
import com.atguigu.lease.model.vo.app.ApartmentItemVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author YouKinn
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2025-06-20 20:18:16
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {
    @Autowired
    ApartmentFacilityMapper apartmentFacilityMapper;

    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        ApartmentItemVo apartmentItemVo = baseMapper.selectApartmentItemVo(id);
        ApartmentDetailVo vo = new ApartmentDetailVo();
        BeanUtils.copyProperties(apartmentItemVo, vo);
        List<GraphVo> graphVoList = apartmentItemVo.getGraphVoList().stream()
                .map(graphInfo -> {
                    GraphVo graphVo = new GraphVo();
                    BeanUtils.copyProperties(graphInfo, graphVo);
                    return graphVo;
                }).collect(Collectors.toList());
        vo.setGraphVoList(graphVoList);
        List<FacilityInfo> facilityInfos = apartmentFacilityMapper.selectFacilityInfosByApartmentId(id);
        vo.setFacilityInfoList(facilityInfos);
        return vo;
    }
}




